package com.xwm93up.javatips.mapper;

import com.xwm93up.javatips.dto.ProductDto;
import com.xwm93up.javatips.po.Product;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import java.util.List;
import java.util.UUID;

/**
 * @Description: desc
 * @Author: xwm93up
 * @Since: 2021/10/27 16:39
 */
@Mapper(imports = {UUID.class})
public interface ProductMapper {
    ProductMapper INSTANCE = Mappers.getMapper(ProductMapper.class);

    List<ProductDto> toDto(List<Product> product);

    @Mapping(source = "count", target = "count", defaultValue = "1")
    @Mapping(target = "id", constant = "-1L")
    @Mapping(target = "productSn", expression = "java(UUID.randomUUID().toString())")
    ProductDto toDto(Product product);
}
